
<h1><span class="yiyi-st" id="yiyi-12">numpy.packbits</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.packbits.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.packbits.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.packbits"><span class="yiyi-st" id="yiyi-13"> <code class="descclassname">numpy.</code><code class="descname">packbits</code><span class="sig-paren">(</span><em>myarray</em>, <em>axis=None</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-14">将二进制值数组的元素包含在uint8数组中的位中。</span></p>
<p><span class="yiyi-st" id="yiyi-15">通过在末尾插入零位将结果填充为全字节。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-16">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-17"><strong>myarray</strong>：array_like</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-18">整数类型数组，其元素应打包为位。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-19"><strong>axis</strong>：int，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-20">进行位打包的尺寸。</span><span class="yiyi-st" id="yiyi-21"><code class="docutils literal"><span class="pre">None</span></code>意味着压缩数组。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-22">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-23"><strong>打包</strong>：ndarray</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-24">uint8的数组，其元素表示对应于输入元素的逻辑（0或非零）值的位。</span><span class="yiyi-st" id="yiyi-25"><em class="xref py py-obj">打包</em>的形状与输入具有相同的维数（除非<em class="xref py py-obj">轴</em>为无，在这种情况下输出为1-D）。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-26">也可以看看</span></p>
<dl class="last docutils">
<dt><span class="yiyi-st" id="yiyi-27"><a class="reference internal" href="numpy.unpackbits.html#numpy.unpackbits" title="numpy.unpackbits"><code class="xref py py-obj docutils literal"><span class="pre">unpackbits</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-28">将uint8数组的元素解包成二进制值输出数组。</span></dd>
</dl>
</div>
<p class="rubric"><span class="yiyi-st" id="yiyi-29">例子</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[[</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span>
<span class="gp">... </span>               <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">]],</span>
<span class="gp">... </span>              <span class="p">[[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>               <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">]]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">packbits</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span>
<span class="go">array([[[160],[64]],[[192],[32]]], dtype=uint8)</span>
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-30">注意，在二进制160 = 1010 0000,64 = 0100 0000,192 = 1100 0000和32 = 0010 0000中。</span></p>
</dd></dl>
